//
//  BCStuffChooseViewController.m
//  BangcaiBuy
//
//  Created by lsy on 16/6/13.
//  Copyright © 2016年 BCB. All rights reserved.
//

#import "BCStuffChooseViewController.h"
#import "WKPageView.h"
@interface BCStuffChooseViewController ()<WKPageViewDataSource,WKPageViewDelegate>
@property (nonatomic, strong) NSArray *items;
@property (nonatomic, weak)   WKPageView *pageView;
@end


@implementation BCStuffChooseViewController
- (instancetype)initWithIndex:(NSIndexPath *)index
{
    self = [super init];
    if (self) {
        self.ClickIndex = index;
        [self getValue];
        [self getView];
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;

}

- (void)getValue
{
    self.items = [NSArray arrayWithObjects:@"蔬菜",@"肉类",@"海鲜",@"水果",@"酒水饮料",@"成品熟食",@"粮油调料",@"厨房用品", nil];
}

- (void)getView
{
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    WKPageView *pageView = [[WKPageView alloc] initWithFrame:self.view.bounds];
    pageView.dataSource = self;
    pageView.delegate = self;
    pageView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:pageView];
    self.pageView = pageView;

}


#pragma mark - page view datasource
// Menu的标题用NSArray封装，内为NSString
- (NSArray *)menuItemsForMenuViewInPageView:(WKPageView *)pageView{
    return self.items;
}

- (WKPageCell *)pageView:(WKPageView *)pageView cellForIndex:(NSInteger)index{
    static NSString *identifier = @"pageCell";
    WKPageCell *cell = [pageView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[WKPageCell alloc] initWithIdentifier:identifier];
    }
    cell.backgroundColor = [UIColor randomColor];
    return cell;
}
// 若不实现，默认红黑，为保证字体颜色渐变，请尽量选用RGBA来创建UIColor
- (UIColor *)titleColorOfMenuItemInPageView:(WKPageView *)pageView withState:(WKMenuItemTitleColorState)state{
    if (state == WKMenuItemTitleSizeStateNormal) {
        return [UIColor colorWithRed:0  green:0  blue:0.1 alpha:1];;
    }else if (state == WKMenuItemTitleSizeStateSelected)
    {
        return [UIColor colorWithRed:0.426  green:0.603  blue:0.479 alpha:1];
    }else
    {
        return [UIColor redColor];
    }
}

// 若不实现,默认为30
- (CGFloat)pageView:(WKPageView *)pageView heightForMenuView:(WKMenuView *)menuView{
    return 50;
}
// 若不实现，默认为15/18
- (CGFloat)titleSizeOfMenuItemInPageView:(WKPageView *)pageView withState:(WKMenuItemTitleSizeState)state{
    switch (state) {
        case WKMenuItemTitleSizeStateNormal:
            return 16;
            break;
        case WKMenuItemTitleSizeStateSelected:
            return 18;
        default:
            break;
    }
}
// 若不实现，默认为灰色
- (UIColor *)backgroundColorOfMenuViewInPageView:(WKPageView *)pageView{
    return [UIColor colorWithRed:0.949  green:0.949  blue:0.949 alpha:1];
}
// MenuView内部各个item的宽度，若标题过长可自行设置，默认为60
- (CGFloat)pageView:(WKPageView *)pageView widthForMenuItemAtIndex:(NSInteger)index{
    return 100;
}

@end
